/**
 * @author zhu
 * @date 2024-03-19
 */
public class TicketSellThread implements Runnable{
    /**
     * 电影票
     */
    private int ticketCount = 50;
    @Override
    public void run() {
        while (ticketCount >= 1){
            sell();
        }
    }
    private synchronized void sell() {
        if (ticketCount > 0){
            System.out.println(Thread.currentThread().getName() + "卖出了第" + ticketCount + "张票");
            ticketCount--;
        }
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }
}
